home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / VBSamples / Demos / AirHockey / cRoom.cls < prev    next >
Encoding:
Visual Basic class definition  |  2001-10-08  |  3.9 KB  |  122 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "cRoom"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. Private Const mnRoomX As Single = 0
  16. Private Const mnRoomY As Single = 2
  17. Private Const mnRoomZ As Single = 0
  18.  
  19. Private Const mnBarRoomX As Single = 0
  20. Private Const mnBarRoomY As Single = -5
  21. Private Const mnBarRoomZ As Single = 0
  22.  
  23. Private Const mnLobbyScaleX As Single = 8
  24. Private Const mnLobbyScaleY As Single = 5
  25. Private Const mnLobbyScaleZ As Single = 9
  26.  
  27. Private moRoom As CD3DFrame               ' Our Room frame
  28. Private moOfficeRoom As CD3DFrame               ' Our Room frame
  29.  
  30. Public DrawRoom As Boolean 'Should we draw the room at all
  31. Public BarRoom As Boolean 'Should we draw the bar or the MS lobby
  32.  
  33. 'Methods
  34. Public Sub Init(ByVal sMedia As String, sRoom As String, sLobby As String)
  35.     Set moRoom = D3DUtil_LoadFromFile(AddDirSep(sMedia) & sRoom, Nothing, Nothing)
  36.     Set moOfficeRoom = D3DUtil_LoadFromFile(AddDirSep(sMedia) & sLobby, Nothing, Nothing)
  37. End Sub
  38.  
  39. Public Sub CleanupFrame()
  40.     If Not (moRoom Is Nothing) Then moRoom.Destroy
  41.     If Not (moOfficeRoom Is Nothing) Then moOfficeRoom.Destroy
  42.     Set moRoom = Nothing
  43.     Set moOfficeRoom = Nothing
  44. End Sub
  45.  
  46. Public Sub Render(dev As Direct3DDevice8)
  47.     Dim matRoom As D3DMATRIX
  48.     Dim matScale As D3DMATRIX
  49.     
  50.     If DrawRoom Then
  51.         If BarRoom Then
  52.             'First the room
  53.             D3DXMatrixIdentity matRoom
  54.             D3DXMatrixTranslation matRoom, mnBarRoomX, mnBarRoomY, mnBarRoomZ
  55.             moRoom.SetMatrix matRoom
  56.             moRoom.Render g_dev
  57.         Else
  58.             'First the room
  59.             D3DXMatrixIdentity matRoom
  60.             D3DXMatrixTranslation matRoom, mnRoomX, mnRoomY, mnRoomZ
  61.             D3DXMatrixScaling matScale, mnLobbyScaleX, mnLobbyScaleY, mnLobbyScaleZ
  62.             D3DXMatrixMultiply matRoom, matRoom, matScale
  63.             moOfficeRoom.SetMatrix matRoom
  64.             moOfficeRoom.Render g_dev
  65.         End If
  66.     End If
  67. End Sub
  68.  
  69. Public Function FadeMesh(FadeInterval As Single) As Boolean
  70.     Dim lNumMaterial As Long
  71.     Dim lCount As Long
  72.     Dim oMaterial As D3DMATERIAL8
  73.     Dim fDoneFading As Boolean
  74.     Dim oMesh As CD3DMesh
  75.     Dim nInternalInterval As Single
  76.     Static lFadeTime As Long
  77.     
  78.     FadeMesh = True
  79.     nInternalInterval = FadeInterval
  80.     If lFadeTime = 0 Then
  81.         lFadeTime = timeGetTime
  82.         Exit Function 'We'll do the fade next render pass
  83.     End If
  84.     nInternalInterval = (((timeGetTime - lFadeTime) / 1000000) * nInternalInterval)
  85.     
  86.     If Not DrawRoom Then Exit Function
  87.     fDoneFading = True
  88.     If BarRoom Then
  89.         Set oMesh = moRoom.FindChildObject("room", 0)
  90.     Else
  91.         Set oMesh = moOfficeRoom.FindChildObject("Unnamed_0", 0)
  92.     End If
  93.     lNumMaterial = oMesh.GetMaterialCount
  94.     For lCount = 0 To lNumMaterial - 1
  95.         oMaterial = oMesh.GetMaterial(lCount)
  96.         If nInternalInterval > 0 And oMaterial.diffuse.a <= 1 Then
  97.             oMaterial.diffuse.a = oMaterial.diffuse.a + nInternalInterval
  98.             fDoneFading = False
  99.         ElseIf nInternalInterval < 0 And oMaterial.diffuse.a >= -1 Then
  100.             oMaterial.diffuse.a = oMaterial.diffuse.a + nInternalInterval
  101.             fDoneFading = False
  102.         End If
  103.         oMesh.SetMaterial lCount, oMaterial
  104.     Next
  105.     FadeMesh = fDoneFading
  106. End Function
  107.  
  108.  
  109. Private Sub Class_Initialize()
  110.     DrawRoom = True
  111.     Set moRoom = Nothing
  112.     Set moOfficeRoom = Nothing
  113. End Sub
  114.  
  115. Private Sub Class_Terminate()
  116.     If Not (moRoom Is Nothing) Then moRoom.Destroy
  117.     If Not (moOfficeRoom Is Nothing) Then moOfficeRoom.Destroy
  118.     
  119.     Set moRoom = Nothing
  120.     Set moOfficeRoom = Nothing
  121. End Sub
  122.